home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3.iso / chapte18 / sendstr.c < prev    next >
C/C++ Source or Header  |  1996-04-29  |  6KB  |  210 lines

  1.  
  2. #include <stdio.h>
  3. #include "SendStr.h"
  4.  
  5. HINSTANCE hInst;   // current instance
  6.  
  7. LPCTSTR lpszAppName = "MyApp";
  8. LPCTSTR lpszTitle   = "mciSendString()"; 
  9.  
  10.  
  11. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  12.  
  13.  
  14. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  15.                       LPTSTR lpCmdLine, int nCmdShow)
  16. {
  17.    MSG      msg;
  18.    HWND     hWnd; 
  19.    WNDCLASS wc;
  20.  
  21.    wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  22.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  23.    wc.cbClsExtra    = 0;                      
  24.    wc.cbWndExtra    = 0;                      
  25.    wc.hInstance     = hInstance;              
  26.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  27.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  28.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  29.    wc.lpszMenuName  = lpszAppName;              
  30.    wc.lpszClassName = lpszAppName;              
  31.  
  32.    if ( IS_WIN95 )
  33.    {
  34.       if ( !RegisterWin95( &wc ) )
  35.          return( FALSE );
  36.    }
  37.    else if ( !RegisterClass( &wc ) )
  38.       return( FALSE );
  39.  
  40.    hInst = hInstance; 
  41.  
  42.    hWnd = CreateWindow( lpszAppName, 
  43.                         lpszTitle,    
  44.                         WS_OVERLAPPEDWINDOW, 
  45.                         CW_USEDEFAULT, 0, 
  46.                         CW_USEDEFAULT, 0,  
  47.                         NULL,              
  48.                         NULL,              
  49.                         hInstance,         
  50.                         NULL               
  51.                       );
  52.  
  53.    if ( !hWnd ) 
  54.       return( FALSE );
  55.  
  56.    ShowWindow( hWnd, nCmdShow ); 
  57.    UpdateWindow( hWnd );         
  58.  
  59.    while( GetMessage( &msg, NULL, 0, 0) )   
  60.    {
  61.       TranslateMessage( &msg ); 
  62.       DispatchMessage( &msg );  
  63.    }
  64.  
  65.    return( msg.wParam ); 
  66. }
  67.  
  68.  
  69. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  70. {
  71.     WNDCLASSEX wcex;
  72.  
  73.    wcex.style         = lpwc->style;
  74.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  75.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  76.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  77.    wcex.hInstance     = lpwc->hInstance;
  78.    wcex.hIcon         = lpwc->hIcon;
  79.    wcex.hCursor       = lpwc->hCursor;
  80.    wcex.hbrBackground = lpwc->hbrBackground;
  81.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  82.    wcex.lpszClassName = lpwc->lpszClassName;
  83.  
  84.    // Added elements for Windows 95.
  85.    //...............................
  86.    wcex.cbSize = sizeof(WNDCLASSEX);
  87.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  88.                             IMAGE_ICON, 16, 16,
  89.                             LR_DEFAULTCOLOR );
  90.             
  91.    return RegisterClassEx( &wcex );
  92. }
  93.  
  94. #define MSG_LEN          1024
  95.  
  96. char       msg[MSG_LEN+1];
  97.  
  98. HWND       hListBox = NULL;
  99. MCIERROR   rc;
  100. UINT       uDeviceId = 0;
  101.  
  102. VOID SendString(HWND hWnd, LPCTSTR lpszCmd);
  103.  
  104.  
  105. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  106. {
  107.    switch( uMsg )
  108.    {
  109.       case WM_CREATE :
  110.               // Create ListBox
  111.               //...............
  112.  
  113.               hListBox = CreateWindow( "LISTBOX", "",    
  114.                                        WS_CHILD | LBS_NOTIFY | 
  115.                                        WS_VSCROLL | WS_BORDER | 
  116.                                        WS_VISIBLE | LBS_NOINTEGRALHEIGHT, 
  117.                                        0, 0, 
  118.                                        0, 0,  
  119.                                        hWnd,              
  120.                                        (HMENU)101,              
  121.                                        hInst,         
  122.                                        NULL );
  123.               break;
  124.  
  125.       case WM_SIZE :
  126.               MoveWindow( hListBox, 0, 0, 
  127.                           LOWORD( lParam ), 
  128.                           HIWORD( lParam ), TRUE );
  129.               break;
  130.  
  131.       case WM_COMMAND :
  132.               switch( LOWORD( wParam ) )
  133.               {
  134.                  case IDM_TEST:
  135.                         {
  136.                            SendMessage(hListBox, LB_RESETCONTENT, 0, 0);
  137.  
  138.                            SendString(hWnd, "open Sample2.wav type waveaudio alias song");
  139.                            SendString(hWnd, "set song time format samples");
  140.                            SendString(hWnd, "play song from 1 wait");
  141.                            SendString(hWnd, "close song");
  142.                         }
  143.                         break;
  144.  
  145.                  case IDM_ABOUT :
  146.                         DialogBox( hInst, "AboutBox", hWnd, About );
  147.                         break;
  148.  
  149.                  case IDM_EXIT :
  150.                         DestroyWindow( hWnd );
  151.                         break;
  152.               }
  153.               break;
  154.  
  155.       case WM_DESTROY :
  156.               PostQuitMessage(0);
  157.               break;
  158.  
  159.       default :
  160.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  161.    }
  162.  
  163.    return( 0L );               
  164. }
  165.  
  166.  
  167. VOID SendString(HWND hWnd, LPCTSTR lpszCmd)
  168. {
  169.    SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)lpszCmd);
  170.    UpdateWindow(hListBox);
  171.  
  172.    mciSendString(lpszCmd, msg, MSG_LEN, (HANDLE)hWnd);
  173.  
  174.    if ( strlen(msg) > 0)
  175.        SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)msg);
  176. }
  177.  
  178.  
  179.  
  180. LRESULT CALLBACK About( HWND hDlg,           
  181.                         UINT message,        
  182.                         WPARAM wParam,       
  183.                         LPARAM lParam)
  184. {
  185.    switch (message) 
  186.    {
  187.        case WM_INITDIALOG: 
  188.                return (TRUE);
  189.  
  190.        case WM_COMMAND:                              
  191.                if (   LOWORD(wParam) == IDOK         
  192.                    || LOWORD(wParam) == IDCANCEL)    
  193.                {
  194.                        EndDialog(hDlg, TRUE);        
  195.                        return (TRUE);
  196.                }
  197.                break;
  198.    }
  199.  
  200.    return (FALSE); 
  201. }
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.